﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.Common
{
  public  class GetCheckRGBHelper
    {
       public static string GetCheckRGB(System.Drawing.Color clr,DataTable dtRGB)
       {
           try
           {
               string rgbInfo;
               int iAlpha = 255;
               int iRed = (int)clr.R;
               int iGreen = (int)clr.G;
               int iBlue = (int)clr.B;

               DataRow[] dr = dtRGB.Select(" 1=1 and COLOR_RED='" + iRed + "' and COLOR_GREEN='" + iGreen + "' and COLOR_BLUE='" + iBlue + "'");
               rgbInfo = "RGB:" + clr.R.ToString() + "," + clr.G.ToString() + "," + clr.B.ToString();

               if (dr.Count() != 0)
               {
                   string STATION_NAME = dr[0]["STATION_NAME"].ToString();
                   string BLOCK_CODE = dr[0]["BLOCK_CODE"].ToString();
                   string BLOCK_NAME = dr[0]["BLOCK_NAME"].ToString();
                   if (STATION_NAME.Contains("_"))//工作站级
                   {
                       return BLOCK_CODE + "_" + BLOCK_NAME + "\r\n" + "\r\n" + rgbInfo;
                   }
                   else//分厂或其他
                   {
                       return BLOCK_CODE + "_" + BLOCK_NAME + "\r\n"
                              + "实时产量：" + (iRed + iGreen + iBlue).ToString() + "\r\n" + "\r\n"
                              + rgbInfo;
                   }
               }
               return "无效区域" + "\r\n" + "\r\n" + rgbInfo;
           }
           catch(Exception ex)
           {
               return ex.Message;
           }          
       }
    }
}
